#!/usr/bin/env python3
from multiprocessing import Queue#队列
import requests
import threading #并发库
from fake_useragent import UserAgent#载入请求头包

class DirScan(threading.Thread):#继承父类
    def __init__(self,queue):
        threading.Thread.__init__(self)#初始化线程类init方法
        self.queue = queue#初始化队列
    def run(self):#在threading.Thread中run方法会随start开启而调用
        #获取队列url
        while not self.queue.empty():
            url = self.queue.get()#接收队列
            try:
                headers= {
                    "UserAgent":UserAgent().random
                }
                response = requests.get(url = url,headers=headers,timeout=2)#超时时间2s
                if response.status_code == 200:
                    print("[+] %s"% url)
            except:
                #print("[-] %s \n",url)
                pass
#定义多线程开启方法
def start(url,file_name,count):
    queue = Queue()
    with open("{}.txt".format(file_name),"r",encoding = "utf-8")as file:
        for i in file:
            queue.put(url+"/"+i.rstrip("\n").strip("\r"))#去除收尾空格和换行传入队列
    #多线程
    threads = []#定义一个列表用于储存多线程
    thread_count = int(count)
    for i in range(thread_count):
        threads.append(DirScan(queue))
    for t in threads:
        t.start()
    for t in threads:
        t.join()

if __name__ == "__main__":
    start(url ="https://www.bxidx.com",file_name="dict",count=5)
#url格式：https://www.bxidx.com
#file_name格式:dict
#count格式：int
